class emiconfig::dpmhead {
  #$atlas_env = {
  #  "LFC_HOST"            => "prod-lfc-atlas-ro.cern.ch",
  #  "LFC_CONRETRY"        => 0,
  #  "GLOBUS_THREAD_MODEL" => "pthread",
  #  "CSEC_MECH"           => "ID"
  #}
  #$atlas_fed = {
  #  name           => 'atlas',
  #  fed_host       => 'atlas-xrd-asia.grid.sinica.edu.tw',
  #  xrootd_port    => 1094,
  #  cmsd_port      => 1098,
  #  local_port     => 11000,
  #  namelib_prefix => '/dpm/ihep.ac.cn/home/atlas',
  #  namelib        => 'XrdOucName2NameLFC.so root=/dpm/cern.ch/home/atlas match=dpmhost.example.com',
  #  setenv         => $atlas_env,
  #  paths          => [ '/atlas', '/atlas/scratch' ]
  #}
  #$cms_fed = {
  #  name           => 'cms',
  #  fed_host       => 'xrootd-cms.infn.it',
  #  all_sitename   => 'T2_CN_Beijing',
  #  cmsd_port      => 1213,
  #  local_port     => 11001,
  #  direct         => 'true' ,
  #  namelib_prefix => "/dpm/ihep.ac.cn/home/cms",
  #  namelib        => "libXrdCmsTfc.so file:/etc/xrootd/storage.xml?protocol=direct",
  #  paths          => [ '/store' ]
  #}
  #$cmslocal_fed = {
  #  name           => 'cmslocal',
  #  all_sitename   => 'T2_CN_Beijing',
  #  fed_host       => 'ccsrm.ihep.ac.cn',
  #  xrootd_port    => 1094, 
  #  local_port     => 11011,
  #  namelib_prefix => "/dpm/ihep.ac.cn/home/cms",
  #  namelib        => "libXrdCmsTfc.so file:/etc/xrootd/storage.xml?protocol=direct",
  #  paths          => [ '/store' ]
  #}

  class{"dpm::headnode":
    localdomain                   => 'ihep.ac.cn',
    db_user                       => 'dpmmgr',
    db_pass                       => 'lcg123',
    db_host                       => 'localhost',
    disk_nodes                    => ['dpmds01.ihep.ac.cn'],
    local_db                      => true,
    mysql_root_pass               => 'lcg123',
    token_password                => 'kwpoMyvcusgdbyyws6gfcxhntkLoh8jilwivnivel',
    xrootd_sharedkey              => 'DXjgDTkK55fnyFr8gW1RcYv0pV7vkcWmZyHr9f4aoc8=',
    #xrootd_async                  => 'off',
    configure_dpm_xrootd_checksum => true,
    site_name                     => 'BEIJING-LCG2',
    volist                        => ["lhcb", "biomed", "dteam", "ops"],
    new_installation              => false,
    memcached_enabled             => true,
    dpmmgr_uid                    => 500,
    dpmmgr_gid                    => 500,
    http_macaroon_secret          => 'ioJSoODJOOPJIojOSIojoIHiGyugUYgUGGuyguyGgUYgiugJ9781098usdfguy5ijuyIfpojiogyftIOFtylOFytu675873',
    configure_dome                => true,
    configure_domeadapter         => true,
    configure_legacy              => false,
    host_dn                       => '/C=CN/O=HEP/O=IHEP/OU=CC/CN=ccsrm.ihep.ac.cn',
    pools                         => ['opsdteam:200M','atlas:200M','lhcb:100M','cms:200M'],
    gridftp_redirect              => true,
    configure_star                => true,   # enable apel accounting
    configure_gridmap             => false,
    filesystems                  => [
      "opsdteam:dpmds01.ihep.ac.cn:/storage/disk01d1p1",
      "lhcb:dpmlhcb01.ihep.ac.cn:/storage/lhcb01_01",
      "lhcb:dpmlhcb01.ihep.ac.cn:/storage/lhcb01_02",
      "lhcb:dpmlhcb01.ihep.ac.cn:/storage/lhcb01_03",
      "lhcb:dpmlhcb01.ihep.ac.cn:/storage/lhcb01_04",
      "lhcb:dpmlhcb01.ihep.ac.cn:/storage/lhcb01_05",
      "lhcb:dpmlhcb01.ihep.ac.cn:/storage/lhcb01_06",
      ],
    groupmap                                                               => {
      "vomss://voms2.hellasgrid.gr:8443/voms/dteam?/dteam/Role=lcgadmin"   => "dteam",
      "vomss://voms2.hellasgrid.gr:8443/voms/dteam?/dteam/Role=production" => "dteam",
      "vomss://voms2.hellasgrid.gr:8443/voms/dteam?/dteam"                 => "dteam",
      "vomss://voms2.cern.ch:8443/voms/atlas?/atlas/Role=lcgadmin"         => "atlas",
      "vomss://voms2.cern.ch:8443/voms/atlas?/atlas/Role=production"       => "atlas",
      "vomss://voms2.cern.ch:8443/voms/atlas?/atlas"                       => "atlas",
      "vomss://voms2.cern.ch:8443/voms/cms?/cms/Role=lcgadmin"         => "cms",
      "vomss://voms2.cern.ch:8443/voms/cms?/cms/Role=production"       => "cms",
      "vomss://voms2.cern.ch:8443/voms/cms?/cms"                       => "cms",
      "vomss://voms2.cern.ch:8443/voms/lhcb?/lhcb/Role=lcgadmin"           => "lhcb",
      "vomss://voms2.cern.ch:8443/voms/lhcb?/lhcb/Role=production"         => "lhcb",
      "vomss://voms2.cern.ch:8443/voms/lhcb?/lhcb"                         => "lhcb",
      "vomss://voms2.cern.ch:8443/voms/ops?/ops"                           => "ops",
      "vomss://lcg-voms2.cern.ch:8443/voms/atlas?/atlas/Role=lcgadmin"     => "atlas",
      "vomss://lcg-voms2.cern.ch:8443/voms/atlas?/atlas/Role=production"   => "atlas",
      "vomss://lcg-voms2.cern.ch:8443/voms/atlas?/atlas"                   => "atlas",
      "vomss://lcg-voms2.cern.ch:8443/voms/cms?/cms/Role=lcgadmin"     => "cms",
      "vomss://lcg-voms2.cern.ch:8443/voms/cms?/cms/Role=production"   => "cms",
      "vomss://lcg-voms2.cern.ch:8443/voms/cms?/cms"                   => "cms",
      "vomss://lcg-voms2.cern.ch:8443/voms/lhcb?/lhcb/Role=lcgadmin"       => "lhcb",
      "vomss://lcg-voms2.cern.ch:8443/voms/lhcb?/lhcb/Role=production"     => "lhcb",
      "vomss://lcg-voms2.cern.ch:8443/voms/lhcb?/lhcb"                     => "lhcb",
      "vomss://lcg-voms2.cern.ch:8443/voms/ops?/ops"                       => "ops",
      "vomss://cclcgvomsli01.in2p3.fr:8443/voms/biomed?/biomed"            => "biomed",
      "vomss://voms.cc.kek.jp:8443/voms/belle?/belle/Role=lcgadmin"        => "belle",
      "vomss://voms.cc.kek.jp:8443/voms/belle?/belle/Role=production"      => "belle",
      "vomss://voms.cc.kek.jp:8443/voms/belle?/belle/Role=pilot"           => "belle",
      "vomss://voms.cc.kek.jp:8443/voms/belle?/belle"                      => "belle",
    },
    #dpm_xrootd_fedredirs =>   {"atlas" => $atlas_fed, "cms" => $cms_fed, "cmslocal" => $cmslocal_fed},
  }
  #package {"apel-ssm":
  #  ensure  => 'installed',
  #  before  => Yumrepo['site']
  #}
  #file {'/etc/cron.daily/dpm-accounting':
  #  mode       =>  '755',
  #  owner      =>  'root',
  #  group      =>  'root',
  #  source     =>  "puppet:///modules/emiconfig/dpm-accounting",
  #  require    => Package['apel-ssm'],
  #}
  ## publishing json file for storage accounting
  cron {
      'dpm-storage-summary':
          command         => '/usr/bin/dpm-storage-summary.py --path /dpm/ihep.ac.cn/home/SRR --log-level=DEBUG --log-file=/var/log/dpm-srr.log',
          user            => 'root',
          minute          => '*/15';
  }

  class { 'limits':
    purge_limits_d_dir => false,
  }
   limits::limits { 'user_nofile':
    ensure     => present,
    user       => '*',
    limit_type => 'nofile',
    soft       => '65535',
    hard       => '65535',
  }
   limits::limits { 'user_nproc':
    ensure     => present,
    user       => '*',
    limit_type => 'nproc',
    soft       => '65535',
    hard       => '65535',
  }
# add mysql max_connections check
  file {'/root/bin/check_mysql.sh':
    mode       =>  '755',
    owner      =>  'root',
    group      =>  'root',
    source     =>  "puppet:///modules/emiconfig/check_mysql.sh",
  } ->
  cron{'check_mysql':
    command => "/root/bin/check_mysql.sh >> /var/log/check_mysql.log",
    user    => 'root',
    minute  => '*/5',
    hour    => '*',
  }
  # add addional vo for dpm
  voms::client{'cepc':
        servers  => [{server => 'voms.ihep.ac.cn',
                   port   => '15005',
                   dn    => '/C=CN/O=HEP/OU=CC/O=IHEP/CN=voms.ihep.ac.cn',
                   ca_dn => '/C=CN/O=HEP/CN=Institute of High Energy Physics Certification Authority',
                  }]
  }
  voms::client{'juno':
        servers  => [{server => 'voms.ihep.ac.cn',
                   port   => '15008',
                   dn    => '/C=CN/O=HEP/OU=CC/O=IHEP/CN=voms.ihep.ac.cn',
                   ca_dn => '/C=CN/O=HEP/CN=Institute of High Energy Physics Certification Authority',
                  }]
  }
  voms::client{'belle':
        servers  => [{server => 'voms.cc.kek.jp',
                   port   => '15020',
                   dn    => '/C=JP/O=KEK/OU=CRC/CN=host/voms.cc.kek.jp',
                   ca_dn => '/C=JP/O=KEK/OU=CRC/CN=KEK GRID Certificate Authority',
                  },
                 {server => 'grid-voms.desy.de',
                   port   => '15020',
                   dn    => '/DC=org/DC=terena/DC=tcs/C=DE/ST=Hamburg/O=Deutsches Elektronen-Synchrotron DESY/CN=grid-voms.desy.de',
                   ca_dn => '/C=NL/O=GEANT Vereniging/CN=GEANT eScience SSL CA 4',
                  }
                  ]
  }
}
